﻿// SwiInstruction.cs
// Software interrupt instruction class


using System;


namespace armsim
{

    /// <summary>
    /// Class for an SWI instruction in an Arm Architecture. Does Software Interrupts
    /// </summary>
    public class SwiInstruction : BaseInstruction
    {

        /// <summary>
        /// Contains the code for the software interrupt
        /// </summary> 
        public uint Immediate24 { get; protected set; }

        /// <summary>
        /// Initializes a new SwiInstruction. Sets the Immediate24 field
        /// </summary>
        /// <param name="instruction"></param>
        public SwiInstruction(uint instruction) : base(instruction)
        {
            this.Immediate24 = VirtualMemory.ExtractBits(instruction, 0, 23);
        }

        /// <summary>
        /// Executes the SWI instruction
        /// </summary>
        /// <param name="cpu">central processing unit</param>
        public override void Execute(VirtualCPU cpu)
        {
            // Stop the program.
        }

        /// <summary>
        /// Returns the assembly language that produced the arm instruction
        /// </summary>
        /// <param name="cpu">central processing unit</param>
        /// <returns>the assembly string</returns>
        public override string ToAssembly(VirtualCPU cpu)
        {
            return String.Format("SWI #{0}", this.Immediate24);
        }

    }

}
